<?php 
echo $this->Html->css('jquery.multiselect');
echo $this->Html->script('jquery.multiselect');
?>
<script type="text/javascript">
<!--


$(function() {
	$(function() {
		
		$("#kenh_id").multiselect({
			   selectedText: "đã chọn # trong # Kênh",
			   checkAllText: 'Chọn Tất cả',
				uncheckAllText: 'Bỏ chọn tất cả',
			   noneSelectedText: '-- Chọn Nhân Viên --'
			});
});
	$(".soluong").keydown(function(e) {
		arr_key = new Array();
		arr_key[8]=8;
		arr_key[9]=9;
		arr_key[35]=35;
		arr_key[36]=36;
		arr_key[37]=37;
		arr_key[39]=39;
		arr_key[46]=46;
        if ( arr_key[e.keyCode]!==undefined) {}
        else {
            if (e.keyCode < 48 || e.keyCode > 57 ) {
                e.preventDefault(); 
            }   
        }
    });
	$( ".thoigian" ).datepicker({
								showOtherMonths: true,
								selectOtherMonths: true,
								changeMonth: true,								
								dateFormat: "dd-mm-yy",
								showOn: "both",
								buttonImage:$('#root').val()+"img/calendar.jpg",
								buttonImageOnly: true
	 							});
	
});
function validate()
{
	if($(".thoigian").val()=='')
	{
		alert('Bạn chưa chọn ngày');
		return false;
	}
	if($("#kenh_id").val()==null)
	{
		alert('Bạn chưa chọn nhân sự');
		return false;
	}
	
	if($(".cap4").val()=='')
	{
		alert('Bạn chưa chọn địa điểm');
		return false;
	}
	return true;
}
//-->
</script>
<div id="tabs">
	<ul>
        <li ><?php echo $this->Html->link(__('Kế hoạch bán hàng lưu động', true), array('controller' => 'chitieungays', 'action' => 'hienkehoach')); ?> </li>
        <li id="current"><?php echo $this->Html->link(__('Thêm kế hoạch', true), array('controller' => 'chitieungays', 'action' => 'themchitieu')); ?> </li>
     </ul>  
</div>
<div class="index">
<h2>Kế hoạch bán hàng lưu động</h2>
<?php
$numhh = count($hanghoas); 
echo $form->create('Chitieungay',array('onsubmit'=>'return validate()'));
echo $form->input('root',array('id'=>'root','type'=>'hidden','value'=>$this->webroot));
?>
<table id ='tables'>
<tr>
<th rowspan=2>STT</th>
<th rowspan=2>Đội</th>
<th rowspan=2>Địa Điểm</th>
<th rowspan=2>Ngày</th>
<th rowspan=2>Thành viên tham gia</th>
<th colspan=<?php echo $numhh?>>Chỉ tiêu</th>
<th rowspan=2>Ghi chú</th>
<th rowspan=2>Thao tác</th>
</tr>
<tr>
<?php foreach ($hanghoas as $keyhh =>$valhh):?>
<th><?php echo $valhh ?></th>
<?php endforeach;?>
</tr>
<?php
	$i=0; 
	 foreach ($chitieungays as $chitieungay):
	  $i++;
?>
<tr>
<td><?php echo $i?></td>
<td><?php echo $chitieungay['Kehoachbhld']['tendoi']?></td>
<td><?php echo $chitieungay['Kehoachbhld']['diadiem']?></td>
<td><?php echo date('d-m-Y',strtotime($chitieungay['Kehoachbhld']['thoigian']))?></td>
<td><?php echo $chitieungay['Kehoachbhld']['nhansu']?></td>
<?php foreach ($hanghoas as $keyhh =>$valhh):?>
<td>
<?php
	foreach ($chitieungay['Chitieungay'] as $ctngay)
	{
		if($ctngay['hanghoa_id']==$keyhh)
 			echo $ctngay['soluong'];	
	}
?>
</td>
<?php endforeach;?>
<td><?php echo $chitieungay['Kehoachbhld']['ghichu']?></td>
<td>
<?php echo $html->link('Sửa',array('controller'=>'chitieungays','action'=>'suachitieu',$chitieungay['Kehoachbhld']['id']));?>
<?php echo $html->link('Xóa',array('controller'=>'chitieungays','action'=>'xoakehoach',$chitieungay['Kehoachbhld']['id']));?>
</td>
</tr>
<?php endforeach;?> 
<tr id='them'>
<td><? echo ++$i?></td>
<td><?php echo $form->input('doi',array('label'=>false,'id'=>'doi','type'=>'text' ,'value'=>'Đội '.$i))?></td>
<td><?php //echo $form->input('diadiem',array('label'=>false,'class'=>'diadiem','type'=>'text','value'=>''))?></td>
<td><?php echo $form->input('thoigian',array('label'=>false,'class'=>'thoigian','type'=>'text','value'=>''))?></td>
<td><div id='kenh'><?php echo $form->input('thanhvien',array('id'=>'kenh_id','label'=>'Kênh','multiple'=>"multiple",'options'=>$kenhs,'style'=>'width:100px'))?></div></td>
<!--<td><?php //echo $form->input('thanhvien',array('label'=>false,'id'=>'thanhvien','type'=>'text','value'=>''))?></td>-->
<?php  if($numhh==0)
			echo "<td>Không có Chỉ tiêu</td>"; 
		else
		 foreach ($hanghoas as $keyhh =>$valhh):?>
<td><input class="soluong" name=data[Chitieungay][hanghoa][<?php echo $keyhh?>]></td>
<?php endforeach;?>
<td><?php echo $form->input('ghichu',array('label'=>false,'id'=>'ghichu','type'=>'textarea','value'=>''))?></td>
<td></td>
</tr>
</table>
<fieldset>
<legend> Địa điểm</legend>
<table>
<tr>
<td><?php echo $form->input('cap1',array('label'=>'Tỉnh/Thành Phố','id'=>'cap1','type'=>'select','options'=>$diadiems,'empty'=>' --Chọn Tỉnh/Thành Phố--'))?></td>
<td><div id='cap2'><?php echo $form->input('cap2',array('label'=>'Huyện','class'=>'cap2','type'=>'select','options'=>array(),'empty'=>' --Chọn Quận Huyện--'))?></div></td>
<td><div id='cap3'><?php echo $form->input('cap3',array('label'=>'Xã','class'=>'cap3','type'=>'select','options'=>array(),'empty'=>' --Chọn Xã/Thị Trấn--'))?></div></td>
<td><div id='cap4'><?php echo $form->input('cap4',array('label'=>'Khu vực/Ấp','class'=>'cap4','type'=>'select','options'=>array(),'empty'=>' --Khu vực/Ấp--'))?></div></td>
</tr>

</table>
</fieldset>
<?php //echo $form->input('thanhvien',array('label'=>'Nhân sự','id'=>'thanhvien','type'=>'text','value'=>''))?>
<?php echo $form->end('  Lưu  ');?>
</div>
<?php
$this->Js->get('#cap1')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap2'),
							array('update' => '#cap2','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

$this->Js->get('#cap2')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap3'),
							array('update' => '#cap3','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

$this->Js->get('#cap1')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'emptycap4'),
							array('update' => '#cap4','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

$this->Js->get('#cap2')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'emptycap4'),
							array('update' => '#cap4','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
							
$this->Js->get('#cap3')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap4'),
							array('update' => '#cap4','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
?>